// 加减积分
swig.setFilter('promoterAction', function (input) {
  return input === 1 ? '+' : '-';
});

// 截取积分
swig.setFilter('promoterIntegral', function (input, fixed) {
  return (input / 100).toFixed(fixed === undefined ? 2 : fixed);
});

/**
 * 设置菜单
 */
(function () {
  if (location.pathname === '/promoter/home') {
    ClientBridge.setMenus([{
      name: '查看详情',
      content: '/promoter/details'
    }]);
  }

  else if (location.pathname === '/promoter/rewards' || location.pathname.indexOf('/promoter/behavior/') !== -1) {
    ClientBridge.setMenus([{
      name: '积分规则',
      content: '/promoter/regular'
    }]);
  }
})();

// 接受协议
(function () {
  if (location.pathname !== '/promoter') {
    return false;
  }

  // 点击同意
  $(document).on('click', 'input[name="protocol"]', function () {
    $('.button.submit').toggleClass('disabled', !$(this).is(':checked'));
  });
})();

// 推广的用户
(function () {
  if (location.pathname !== '/promoter/members') {
    return false;
  }

  // 加载更多分页
  loadMoreFactory({
    size: 20,
    url: '/promoter/ajax/members',
    panel: '#members',
    template: '#membersTempl'
  });
})();

// 推广明细
(function () {
  if (location.pathname !== '/promoter/rewards') {
    return false;
  }

  // 注册记录
  loadMoreFactory({
    size: 20,
    url: '/promoter/ajax/rewards?type=BD',
    panel: '#register > .list',
    template: '#templ',
    before: function () {
      return $('#register').is('.active');
    }
  });

  // 活跃记录
  loadMoreFactory({
    size: 20,
    url: '/promoter/ajax/rewards?type=PC',
    panel: '#activity > .list',
    template: '#templ',
    before: function () {
      return $('#activity').is('.active');
    }
  });

  // 下单记录
  loadMoreFactory({
    size: 20,
    url: '/promoter/ajax/rewards?type=XD',
    panel: '#placeorder > .list',
    template: '#templ',
    before: function () {
      return $('#placeorder').is('.active');
    }
  });

})();

// 用户行为明细
(function () {
  if (location.pathname.indexOf('/promoter/behavior/') === -1) {
    return false;
  }

  // 被邀请用户ID
  var invitedId = location.pathname.split('/')[3];

  // 注册记录
  loadMoreFactory({
    size: 20,
    url: '/promoter/ajax/behavior?type=BD&invitedId=' + invitedId,
    panel: '#register > .list',
    template: '#templ',
    before: function () {
      return $('#register').is('.active');
    }
  });

  // 活跃记录
  loadMoreFactory({
    size: 20,
    url: '/promoter/ajax/behavior?type=PC&invitedId=' + invitedId,
    panel: '#activity > .list',
    template: '#templ',
    before: function () {
      return $('#activity').is('.active');
    }
  });

  // 下单记录
  loadMoreFactory({
    size: 20,
    url: '/promoter/ajax/behavior?type=XD&invitedId=' + invitedId,
    panel: '#placeorder > .list',
    template: '#templ',
    before: function () {
      return $('#placeorder').is('.active');
    }
  });
})();
